export default class EventEmitter {
    constructor() {
        this.events = {};
    }
    emit(event, ...args) {
        const events = this.events[event];
        if (Array.isArray(events)) {
            events.forEach(func => func(...args))
        }
    }
    on(event, cb) {
        this.events[event] = (this.events[event] || []).push(cb);
        return () => {
            (this.events[event] = (this.events[event] || []).filter(i => i !== cb))
        }
    }
    once(event, callback) {
        const unbind = this.on(event, (...args) => {
            unbind();
            callback(...args)
        })
        return unbind;
    }
}